home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / grafik / 3d & render tools / irit / contrib / compgrap / crvssrfs / csg.irt < prev    next >
Encoding:
Text File  |  1996-07-16  |  2.3 KB  |  97 lines

  1. #
  2. # Demos for CSG Boolean operations.
  3. #
  4. #                                       (c) Gershon Elber, July 1995
  5. #
  6.  
  7. comment $
  8. pause = procedure():
  9.     printf("Press return to continue:", nil());
  10. $
  11.  
  12. save_mat = view_mat;
  13. resolution = 40;
  14. #
  15. # Examples of the different Boolean operations.
  16. #
  17. view_mat = save_mat * sc( 0.6 );
  18.  
  19. B = box(vector(-1, -1, -0.25), 2, 2, 0.5);
  20. color( B, red );
  21. attrib( B, "dwidth", 2 );
  22.  
  23. C = cylin(vector(0, 0, -0.5), vector(0, 0, 1), 1.1);
  24. color( C, magenta );
  25. attrib( C, "dwidth", 2 );
  26.  
  27. D = convex(B - C);
  28. color( D, yellow );
  29. attrib( D, "dwidth", 4 );
  30. E = convex(C - B);
  31. color( E, yellow );
  32. attrib( E, "dwidth", 4 );
  33. F = convex(B + C);
  34. color( F, yellow );
  35. attrib( F, "dwidth", 4 );
  36. G = convex(B * C);
  37. color( G, yellow );
  38. attrib( G, "dwidth", 4 );
  39.  
  40. interact( list( view_mat, B, C, D ) );
  41.  
  42. interact( list( B, C, E ) );
  43.  
  44. interact( list( B, C, F ) );
  45.  
  46. interact( list( B, C, G ) );
  47.  
  48. comment $
  49.  
  50. interact( D );
  51.  
  52. interact( E );
  53.  
  54. interact( F );
  55.  
  56. interact( G );
  57.  
  58. $
  59.  
  60. #
  61. # A tree of Boolean operations.
  62. #
  63. b1 = box(vector(-0.6, -0.3, 0.0), 1.2, 0.6, 0.6);
  64. c1 = cylin(vector(0.0, -0.25, 0.59), vector(0.0, 0.5, 0.0), 0.55);
  65. s1 = convex(b1 + c1);
  66.  
  67. b2 = box(vector(-0.4, -0.4, -0.1), 0.8, 0.8, 0.35);
  68. s2 = convex(s1 - b2);
  69.  
  70. c2 = cylin(vector(0.0, -0.4, 0.595), vector(0.0, 0.8, 0.0), 0.3);
  71. s3 = convex(s2 - c2);
  72.  
  73. trans_mat = rotz( 40 ) * rotx( -70 ) * scale( vector( 0.3, 0.3, 0.3 ) );
  74. Obj = list( b1 * trans_mat * trans( vector( -0.7, -0.9, 0.0 ) ),
  75.         c1 * trans_mat * trans( vector( -0.1, -0.9, 0.0 ) ),
  76.         s1 * trans_mat * trans( vector( -0.4, -0.3, 0.0 ) ),
  77.         b2 * trans_mat * trans( vector(  0.2, -0.3, 0.0 ) ),
  78.         s2 * trans_mat * trans( vector( -0.1,  0.3, 0.0 ) ),
  79.         c2 * trans_mat * trans( vector(  0.5,  0.3, 0.0 ) ),
  80.         s3 * trans_mat * trans( vector(  0.2,  0.9, 0.0 ) ) );
  81. attrib( Obj, "dwidth", 4 );
  82.  
  83. edge2d = function( x1, y1, x2, y2 ):
  84.     return = ctlpt( E2, x1, y1 ) + ctlpt( E2, x2, y2 );
  85.  
  86. Lines = list( edge2d( -0.6, -0.65, -0.5, -0.4 ),
  87.           edge2d( -0.2, -0.55, -0.3, -0.35 ),
  88.           edge2d( -0.3, 0.05, -0.25, 0.2 ),
  89.           edge2d(  0.1, -0.16, -0.05, 0.25 ),
  90.           edge2d(  0.0, 0.65, 0.1, 0.8 ),
  91.           edge2d(  0.4, 0.6, 0.3, 0.85 ) );
  92. attrib( Lines, "dwidth", 2 );
  93.  
  94. All = list( Lines, Obj ) * scale( vector( 0.7, 0.7, 0.7 ) );
  95. view_mat = rotx( 0 );
  96. interact( list( view_mat, All ) );
  97.